import 'package:flutter/material.dart';

class InspectionListItem extends StatelessWidget {
  final String periodSchemeStatus;
  final String periodSchemeName;
  final String periodFrequency;
  final String tlName;
  final String userNames;
  final Map<String, dynamic>? additionalInfo; //其他的key:value
  final VoidCallback onTap;

  const InspectionListItem({
    Key? key,
    required this.periodSchemeStatus,
    required this.periodSchemeName,
    required this.periodFrequency,
    required this.tlName,
    required this.userNames,
    this.additionalInfo,
    required this.onTap,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Padding(
        padding: const EdgeInsets.symmetric(vertical: 8.0),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            // 左侧部分
            Column(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Image.asset(
                  periodSchemeStatus == '1'
                      ? 'assets/running.png'
                      : 'assets/ending.png',
                  width: 28,
                  height: 28,
                  fit: BoxFit.cover,
                ),
                const SizedBox(height: 8),
                Image.asset(
                  'assets/jiantou.png',
                  width: 12,
                  height: 12,
                  fit: BoxFit.cover,
                ),
              ],
            ),
            const SizedBox(width: 16),
            // 中间部分
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    periodSchemeName,
                    style: const TextStyle(
                      fontSize: 8,
                      fontWeight: FontWeight.bold,
                      color: Colors.black,
                    ),
                  ),
                  const SizedBox(height: 5),
                  Text(
                    '巡检周期: $periodFrequency',
                    style: const TextStyle(
                      fontSize: 8, // 调整字体大小
                      color: Colors.grey, // 灰色字体
                    ),
                  ),
                  Text(
                    '巡检类型: $tlName',
                    style: const TextStyle(
                      fontSize: 8, // 调整字体大小
                      color: Colors.grey, // 灰色字体
                    ),
                  ),
                  Text(
                    '巡检人: $userNames',
                    style: const TextStyle(
                      fontSize: 8, // 调整字体大小
                      color: Colors.grey, // 灰色字体
                    ),
                  ),
                  if (additionalInfo != null) // 检查是否有 additionalInfo
                    ...additionalInfo!.entries.map((entry) {
                      return Text(
                        '${entry.key}: ${entry.value}',
                        style: const TextStyle(
                          fontSize: 12, // 调整字体大小
                          color: Colors.grey, // 灰色字体
                        ),
                      );
                    }).toList(),
                ],
              ),
            ),
            const SizedBox(width: 16),
            // 右侧部分
            Image.asset(
              'assets/weizhi.png',
              width: 28,
              height: 28,
              fit: BoxFit.cover,
            ),
          ],
        ),
      ),
    );
  }
}
